import 'package:flutter/cupertino.dart' hide Action;
import 'package:flutter/material.dart' hide Action;
import 'package:flutter_spinkit/flutter_spinkit.dart';

String _dialogMessage = "Loading...";
bool _isShowing = false;

class ProgressDialog {
  BuildContext _buildContext;

  ProgressDialog(BuildContext buildContext) {
    _buildContext = buildContext;
  }

  void setMessage(String mess) {
    _dialogMessage = mess;
    debugPrint("ProgressDialog message changed: $mess");
  }

  bool isShowing() {
    return _isShowing;
  }

  void hide() {
    _isShowing = false;
    Navigator.of(_buildContext).pop();
    print('ProgressDialog dismissed');
  }

  void show() {
    _isShowing = true;
    showGeneralDialog<dynamic>(
      context: _buildContext,
      barrierColor: Colors.black.withOpacity(0.1),
      transitionDuration: Duration(milliseconds: 200),
      barrierDismissible: true,
      barrierLabel: 'dismiss',
      pageBuilder: (context, animation1, animation2) {
        return Material(
            type: MaterialType.transparency, //透明类型
            child: Center(
              child: Container(
                width: 120.0,
                height: 120.0,
                decoration: ShapeDecoration(
                  color: Colors.black54,
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.all(
                      Radius.circular(8.0),
                    ),
                  ),
                ),
                child: new Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    new SpinKitFadingCircle(
                      color: Colors.white,
                      size: 35.0,
                    ),
                    new Padding(
                      padding: const EdgeInsets.only(
                        top: 20.0,
                      ),
                      child: new Text(
                        _dialogMessage,
                        style:
                            new TextStyle(fontSize: 12.0, color: Colors.white),
                      ),
                    ),
                  ],
                ),
              ),
            ));
      },
    );
  }
}
